package com.ray.monitor.task;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.ray.monitor.common.tools.TimeUtil;
import com.ray.monitor.table.mapper.InvokeDOMapper;


public class CommonTask {


    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;
    @Autowired
    private InvokeDOMapper invokeDOMapper;

    //每天凌晨 00：30分执行
    @Scheduled(cron = "0 30 0 * * ?")
    public void everyDayDo() {
        //每天更新
        AppConsumerOnDayProcess appConsumerOnDayProcess = new AppConsumerOnDayProcess();
        taskExecutor.execute(appConsumerOnDayProcess);
    }


    //每天
    private class AppConsumerOnDayProcess implements Runnable {
        @Override
        public void run() {
            try {
                //每天删除 大于15天的日期的原始数据
                String minDate = TimeUtil.getBeforDateByNumber(new Date(), -15);
                invokeDOMapper.deleteByDate(minDate);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
